home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_d / oleauttr.zip / XLOLE7.ZIP / SAFEOLE.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-04  |  2KB  |  68 lines

  1. unit SafeOLE;
  2. {
  3. // SAFEOLE.PAS (C) 1995 W. Raike
  4. //              ALL RIGHTS RESERVED.
  5. }
  6. interface
  7. {*******************************************************************}
  8. {
  9.   Class TSafeOLEObject inherited from TOLEObject (TOLEAutoClient)
  10.   keeps track of all sub-objects created using a ConnectInterface
  11.   constructor so that they can be freed later.
  12. }
  13. {*******************************************************************}
  14.  
  15. uses
  16.   SysUtils, OleAuto, MemMiser;
  17.  
  18. type
  19.  
  20.   { This class overrides the ConnectInterface constructor so as to
  21.     keep track of all objects created so that they can later be released. }
  22.   TSafeOLEObject = class(TOleObject)
  23.   public
  24.     constructor ConnectInterface(pI : pInterface); override;
  25.     class procedure CreateOobList;
  26.     class procedure FreeOobList;
  27.   end;
  28.  
  29. implementation
  30.  
  31. var
  32.   { Static class member to keep track of all TOLEObjects created
  33.     using ConnectInterface constructors. }
  34.   OobList : TOleObjectList;
  35.  
  36. constructor TSafeOleObject.ConnectInterface(pI : pInterface);
  37. begin
  38.   inherited ConnectInterface(pI);
  39.   if Assigned(OobList) then
  40.     OobList.Add(self);
  41. end;
  42.  
  43. class procedure TSafeOleObject.CreateOobList;
  44. begin
  45.   if not Assigned(Ooblist) then
  46.     OobList := TOleObjectList.Create;
  47. end;
  48.  
  49. class procedure TSafeOleObject.FreeOobList;
  50. var
  51.   i : Integer;
  52. begin
  53.   i := 0;
  54.   if Assigned(OobList) then
  55.   begin
  56.     { Free up any nested OLE objects. }
  57.     while i <= (OobList.Count - 1) do
  58.     begin
  59.       OobList.Items[i].Release;
  60.       Inc(i);
  61.     end;
  62.     OobList.Free;
  63.   end;
  64. end;
  65.  
  66. end.
  67.  
  68.